<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>设备定时开关管理</title>
    <meta name="decorator" content="nblank"/>
    <%@include file="/WEB-INF/views/include/treetable.jsp" %>
    <link href="${ctxStatic}/modules/biz/record/equItemHisList.css" rel="stylesheet" itself="true" />
</head>
<body>
<div class="content container">
    <h2 class="page-title">设备定时开关管理
    </h2>
    <div class="row">
        <div class="col-md-12">
            <section class="widget widget-tabs">
                <header>
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="javascript:;">设备定时开关列表</a></li>
                        <li><a href="${ctx}/biz/switcher/form">定时开关${not empty param.id?'修改':'添加'}</a></li>
                    </ul>
                </header>
                <div class="body tab-content">
                    <div class="tab-pane active clearfix" style="position: relative;">
                        <form:form id="inputForm" modelAttribute="condition" method="post" class="form-inline widget">
                            <input type="hidden" id="pageNo" name="pageNo"/>
                            <input type="hidden" id="pageSize" name="pageSize"/>
                            <input type="hidden" id="admin" value="${ctx}"/>

                            <div class="row pd-first">
                                <div class="col-md-4 col-qc-4  git-first" style="display: ${singleStation == 'yes'?'none':'block'}">
                                    <label class="form-group mg-right-10 pull-left"><span style="color: red;">*</span>站点:</label>
                                    <sys:treeselectExtend id="office" name="office.id" value="${user.office.id}"
                                                    labelName="office.name" labelValue="${user.office.name}"
                                                    title="站点" url="/sys/office/treeDataThree?type=2"
                                                    cssClass="form-control input-transparent" notAllowSelectRoot="true"
                                                    notAllowSelectParent="false" officeGrade="true"/>
                                </div>
                                <div class="col-md-3 col-qc-3 git-two">
                                    <label class="form-group mg-right-10" for="sgroupId"><span style="color: red;">*</span>组查询:</label>
                                    <form:select path="sgroupId" class="selectpicker" data-style="btn-primary">
                                        <form:option value="" label="请选择"/>
                                    </form:select>
                                </div>
                                <div class="col-md-3 col-qc-3 git-two">
                                    <label class="form-group mg-right-10" for="gitemId"><span style="color: red;">*</span>设备查询:</label>
                                    <form:select path="gitemId" class="selectpicker" data-style="btn-primary" >
                                        <form:option value="" label="请选择"/>
                                    </form:select>
                                </div>
                                <div class="col-md-1 col-qc-1 form-group">
                                    <input id="btnSubmit" class="btn btn-primary mg-left-50" type="button" value="查询"/>
                                </div>
                            </div>
                        </form:form>
                        <div class="widget mg-bottom">
                            <div class="list-box" id="inner-content-div">
                                <table id="mainTable" class="table table-striped  table-condensed tree_table overflow-auto">
                                    <thead>
                                    <tr>
                                        <th>暂无数据</th>
                                    </tr>
                                    </thead>
                                    <tbody class="table-cor">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="row" id="pageDiv"></div>
                    </div>
                </div>
            </section>
        </div>
    </div>
</div>
<script type="text/javascript">
    var $btnSubmit = $("#btnSubmit");
    var $sgroup = $("#sgroupId");
    var $gitem = $("#gitemId");
    var $office = $('#officeId');

    var $pageNo = $("#pageNo");
    var $pageSize = $("#pageSize");
    var $pageDiv = $("#pageDiv");
    var $mainTable = $("#mainTable");
    var noData = "无数据";
    var admin = $("#admin").val();
    var modify = "修改";
    var del = "删除";
    $(function () {
        // 进入本页面的默认设置

        //下拉单不可选
        $btnSubmit.attr("disabled", true);
        $sgroup.attr("disabled", true);
        $gitem.attr("disabled", true);
        //清空选项
        $sgroup.find("option:not(:first)").remove();
        $gitem.find("option:not(:first)").remove();
        //刷新
        $sgroup.change().selectpicker('refresh');
        $gitem.change().selectpicker('refresh');

//        组查询的change事件
        $sgroup.on('changed.bs.select', function () {
            $btnSubmit.attr("disabled", true);
            $gitem.attr("disabled", true);
            $gitem.find("option:not(:first)").remove();
            if ($sgroup.val() == "") {
                $gitem.change().selectpicker('refresh');
            } else {
                $.ajax({
                    type: "get",
                    url: "${ctx}/biz/sgcfg/itemlistForTrans",
                    data: {
                        sgroupId: $sgroup.val()
                    },
                    dataType: "json",
                    success: function (data) {
                        $.each(data, function (indexColumn, item) {
                            $("<option value='" + item.gitem.id + "'>" + item.gitem.name + "</option>").appendTo("#gitemId");
                        })
                        $gitem.attr("disabled", false);
                        $gitem.change().selectpicker('refresh');
                    }
                });
            }
        });

//        设备change事件
        $gitem.on('changed.bs.select', function (e) {
            $btnSubmit.attr("disabled", true);
            if ($gitem.val() != "") {
                $.ajax({
                    type: "get",
                    url: "${ctx}/biz/ehRecord/etypeKid",
                    data: {
                        itemId: $gitem.val()
                    },
                    dataType: "json",
                    success: function (data) {
                        $btnSubmit.attr("disabled", false);
                    }
                });
            }
        });

//        表单提交事件
        $btnSubmit.click(function () {
            submitAjax();
        });

        $('#inner-content-div').slimScroll({
            axis: 'x',
            height: $('#inner-content-div').outerHeight(true),
            width: 'auto',
            size: '10px',
            allowPageScroll: true,
            alwaysVisible: true
        }).css("width", "").css("height", "").parent().css("height", "").css("width", "");
    });
    /** jquery 部分结束 */

    /** 表单提交ajax部分 -- 开始 */
    function submitAjax() {
        $btnSubmit.attr("value", "查询中...");
        $.ajax({
            type: "get",
            url: "${ctx}/biz/switcher/switchPage",
            data: {
                officeId: $office.val(),
                sgroupId: $sgroup.val(),
                gitemId: $gitem.val(),
                pageNo: $pageNo.val(),
                pageSize: $pageSize.val()
            },
            dataType: "json",
            success: function (data) {
                $pageDiv.html("");
                $mainTable.find("thead").html("");
                $mainTable.find("tbody").html("");
                var heightTemp;
                if (data.list != null) {
                    $mainTable.find("thead").append("<tr><th>站组名称</th><th>设备名称</th><th>触发时间</th><th>动作</th><th>是否生效</th><th>备注</th><th>操作</th></tr>");
                    $.each(data.list, function (indexColumn, item) {
                        var weeks = item.turnWeek.split(",");
                        var weekStr = "";
                        if (weeks.length > 0) {
                            for (var i = 0; i < weeks.length; i++) {
                                if (i != 0) {
                                    weekStr += "，";
                                }
                                weekStr += getDictLabel(${fns:toJson(fns:getDictList('sys_week'))}, weeks[i]);
                            }
                        }
                        $("<tr><td>" + item.sgroupName + "</td><td>" + item.gitemName + "</td>" +
                                "<td>" + weekStr + '&nbsp;&nbsp;' + item.turnHour + '时' + item.turnMinute + '分' + "</td>" +
                                "<td>" + getDictLabel(${fns:toJson(fns:getDictList('biz_equ_switcher_operate'))}, item.operate) + "</td>" +
                                "<td>" + getDictLabel(${fns:toJson(fns:getDictList('switcher_active'))}, item.active) + "</td>" +
                                "<td>" + ((item.remarks == null) ? '' : item.remarks) + "</td>" +
                                "<td><a href='" + admin + "/biz/switcher/form?officeId=" + item.officeId + "&id=" + item.id + "'>" + modify + "</a>&nbsp;" +
                                "<a href='" + admin + "/biz/switcher/delete?officeId=" + item.officeId + "&id=" + item.id + "' class='no-pjax' onclick=\"confirmx('确认要删除该定时开关吗？', this.href);return false;\">" + del + "</a></td></tr>")
                                .appendTo("#mainTable tbody");
                    });
                    $pageDiv.html("<div class='row'>" + data.html + "</div>");
                    $pageNo.val(data.pageNo);
                    $pageSize.val(data.pageSize);
                    heightTemp = $('.table-cor').outerHeight(true) + 40;
                } else {
                    $("<tr><td align='center'>" + noData + "</td></tr>").appendTo("#mainTable tbody");
                    heightTemp = $('.table-cor').outerHeight(true);
                }
                $btnSubmit.attr("value", "查询");
                $('#inner-content-div').slimScroll({
                    height: heightTemp
                }).css("width", "").css("height", "").parent().css("height", "").css("width", "");
            }
        });
    }
    /** 表单提交ajax部分 -- 结束 */

    /** 分页功能(必须放在jquery外) -- 开始*/
    function page(n, s) {
        $pageNo.val(n);
        $pageSize.val(s);
        submitAjax();
        return false;
    }
    /** 分页功能 -- 结束 */
/**
 * 单站点时启用
    <%--function initSgroup(){--%>
<%--//        $btnSubmit.attr("disabled", true);--%>
<%--//        $sgroup.attr("disabled", true);--%>
        <%--$sgroup.find("option:not(:first)").empty();--%>
<%--//        $gitem.attr("disabled", true);--%>
        <%--$gitem.find("option:not(:first)").empty();--%>
        <%--$.ajax({--%>
            <%--type: "post",--%>
            <%--url: "${ctx}/biz/switcher/sgroupSelect",--%>
            <%--dataType: "json",--%>
            <%--success: function (data) {--%>
                <%--$.each(data, function (indexColumn, item) {--%>
                    <%--$("<option value='" + item.id + "'>" + item.name + "</option>").appendTo("#sgroupId");--%>
                <%--});--%>
                <%--$sgroup.change().selectpicker('refresh');--%>
            <%--}--%>
        <%--});--%>
        <%--$sgroup.attr("disabled", false);--%>
    <%--}--%>


    <%--$(function () {--%>
        <%--if (officeId != null && officeId != "") {--%>
            <%--if(singleStation=='yes'){--%>
                <%--initSgroup();--%>
            <%--}--%>
            <%--submitAjax();--%>
            <%--$btnSubmit.attr("disabled", false);//查询按钮可用--%>
        <%--} else {--%>
<%--//            $btnSubmit.attr("disabled", true);//查询按钮不可用--%>
        <%--}--%>
    <%--});--%>

    /** 站点控件选择功能 **/
    function stationSelect(officeIdVar) {
    $sgroup.attr("disabled", true);
    $gitem.attr("disabled", true);
    $sgroup.find("option:not(:first)").remove();
    $gitem.find("option:not(:first)").remove();

        if (officeIdVar == "") {
            $sgroup.change().selectpicker('refresh');
            $gitem.change().selectpicker('refresh');
        } else {
            $.ajax({
                type: "post",
                url: "${ctx}/biz/switcher/sgroupSelectForSysStation?officeId=" + officeIdVar,
                dataType: "json",
                success: function (data) {
                    $.each(data, function (indexColumn, item) {
                        $("<option value='" + item.id + "'>" + item.name + "</option>").appendTo("#sgroupId");
                    });
                    $sgroup.attr("disabled", false);
                    $sgroup.change().selectpicker('refresh');
                    $gitem.change().selectpicker('refresh');
                }
            });

        }
    }

</script>
</body>
</html>